﻿using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Resources;
using System.Windows.Forms;

namespace ChromiumUpdater
{
    public class Common
    {
        public List<DirectoryInfo> GetBuildDirs()
        {
            var di = new DirectoryInfo(Application.StartupPath);
            var builds = (from d in di.GetDirectories()
                          where d.Name.Length == 5 && d.Name.IsAllDigit()
                          orderby d.CreationTime descending
                          select d).ToList();
            return builds;
        }

        public void SetFormIcon(Form f)
        {
            f.Icon = GetIconFromResources("icoChrome");
        }

        public Icon GetIconFromResources(string name)
        {
            var rm = new ResourceManager("ChromiumUpdater.Properties.Resources", GetType().Assembly);
            return (Icon)rm.GetObject(name);
        }
    }
}
